
/*
 * Copyright (c) 2011-2023, ThinkWide (cnet2001@163.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.thinkwide.data.ormapping.page;

/*
     ######### ##        ##            ###     ###    ##    ##  ##        ##
        ###    ##                      ##      ###   ####   ##            ##
        ##     #######   ##  #######   ##   ##  ##   ####  ###  ##   #######   #####
        ##     ###  ###  ##  ###  ###  ##  ##   ### ##  ## ##   ##  ###  ###  ###  ##
        ##     ##   ###  ##  ###   ##  #####     ## ##  ## ##   ##  ##    ##  #######
        ###    ##   ###  ##  ###   ##  ##  ###   ####   ####    ##  ###  ###  ###
        ##     ##   ###  ##  ###   ##  ##   ###   ###    ###    ##   #######   ######
                                                                          2023-5-18
 */

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 分页数据
 *
 * @author andyzhang
 * @since 2023/06/09
 */
@Data
@NoArgsConstructor
public class MFPage<T> extends MFAbstractPage {
    private List<T> list;

    public static <T> MFPage buildByIndex(List<T> list, int beginIndex, int endIndex, int total) {
        MFPage page = new MFPage();
        page.setList(list);
        page.setBeginIndex(beginIndex);
        page.setEndIndex(endIndex);
        page.setTotal(total);

        page.setPageSize(endIndex - beginIndex + 1);
        page.setPageNum((new Double(Math.ceil(beginIndex / page.getPageSize()))).intValue());
        page.setPageTotal((new Double(Math.ceil(total / page.getPageSize()))).intValue());
        return page;
    }

    public static <T> MFPage buildByPage(List<T> list, int pageNum, int pageSize, int pageTotal) {
        MFPage page = new MFPage();
        page.setList(list);
        page.setPageSize(pageNum);
        page.setPageNum(pageSize);
        page.setPageTotal(pageTotal);

        page.setBeginIndex((pageNum - 1) * pageSize + 1);
        page.setEndIndex(pageNum * pageSize);
        page.setTotal(pageTotal * pageSize);
        return page;
    }

    public MFPage(List<T> list, int pageNum, int pageSize, int pageTotal) {
        this.setList(list);
        this.setPageSize(pageNum);
        this.setPageNum(pageSize);
        this.setPageTotal(pageTotal);

        this.setBeginIndex((pageNum - 1) * pageSize + 1);
        this.setEndIndex(pageNum * pageSize);
        this.setTotal(pageTotal * pageSize);
    }

}
